const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabs: [
      { title: "全部", jk: "all_after_sale" },
      { title: "退款中", jk: "outing" }, 
      { title: "退款成功", jk: "ok_outing" }, 
      { title: "退款失败", jk: "no_outing" }
    ],
    activeIndex: 0, //当前选中的类型
    sliderOffset: 0, //滑块偏移距离
    sliderLeft: 10, //滑块初始left值
    orderList: [], //售后单列表
    //为空提示
    emptyTip: {
      font: "您暂时还没有退款申请哦~",
      imgUrl: "https://jrtest.0791jr.com/WeChat/images/empty-retreat.png"
    },
    isNone: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //初始化我的订单
    wx.request({
      url: app.baseURL + 'Order&a=all_after_sale',
      data: { user_id: app.globalData.userId },
      success: (res) => {
        if (res.statusCode == 200) {
          this.setData({
            orderList: res.data.all_order,
            isNone: !res.data.all_order.length
          })
        }  
      }
    })
  },

  //切换类型
  tabClick: function (e) {
    const jk = e.currentTarget.dataset.jk;
    console.log(jk)
    this.setData({
      //translateX的值就是终点目标距离左边的距离减去初始left的值
      sliderOffset: e.currentTarget.offsetLeft - 10,
      activeIndex: e.currentTarget.id,
      orderList: []
    });
    wx.showLoading({ title: '加载中', mask: true });
    wx.request({
      url: app.baseURL + 'Order&a=' + jk,
      data: { user_id: app.globalData.userId },
      success: (res) => {
        if (res.statusCode == 200) {
          this.setData({
            orderList: res.data.all_order,
            isNone: !res.data.all_order.length
          });
          wx.hideLoading();
        }
      }
    })
  },

  //查看订单详情跳转
  clickSeeDetail(e) {
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/orderDetail/orderDetail?orderId=' + id + '&aftersale=' + true,
    })
  }
})